package org.db2.project.airline.service;

import org.db2.project.airline.dao.AirportDAO;
import org.db2.project.airline.dao.DAOException;
import org.db2.project.airline.dao.impl.HibernateAirportDAO;
import org.db2.project.airline.model.Airport;
import org.db2.project.airline.utils.HibernateHelper;

import java.util.List;

/**
 *
 */
public class AirportService {

    private final AirportDAO airportDAO = new HibernateAirportDAO();

    public AirportService() {
        // empty constructor
    }

    public List<Airport> findAll() throws DAOException {

        try {
            HibernateHelper.beginTransaction();

            List<Airport> airports = airportDAO.findAll();

            HibernateHelper.commitTransaction();

            return airports;
        } catch (DAOException e) {
            HibernateHelper.rollbackTransaction();

            throw e;
        }
    }
}
